{% extends 'todo/base.html' %}

{% block title %}编辑任务 - 考研学习计划{% endblock %}

{% block content %}
<div class="container">
    <div class="row justify-content-center">
        <div class="col-md-8">
            <div class="card shadow-sm">
                <div class="card-header bg-primary text-white">
                    <h4 class="mb-0"><i class="bi bi-pencil"></i> 编辑任务</h4>
                </div>
                <div class="card-body">
                    <form method="post">
                        {% csrf_token %}
                        
                        <div class="mb-3">
                            <label for="title" class="form-label">任务标题 <span class="text-danger">*</span></label>
                            <input type="text" class="form-control" id="title" name="title" 
                                   value="{{ todo.title }}" required>
                        </div>
                        
                        <div class="mb-3">
                            <label for="description" class="form-label">详细描述</label>
                            <textarea class="form-control" id="description" name="description" 
                                      rows="4">{{ todo.description }}</textarea>
                        </div>
                        
                        <div class="row">
                            <div class="col-md-6 mb-3">
                                <label for="category" class="form-label">科目分类</label>
                                <select class="form-select" id="category" name="category">
                                    <option value="">选择科目</option>
                                    {% for category in categories %}
                                    <option value="{{ category.id }}" 
                                            {% if todo.category and category.id == todo.category.id %}selected{% endif %}>
                                        {{ category.name }}
                                    </option>
                                    {% endfor %}
                                </select>
                            </div>
                            
                            <div class="col-md-6 mb-3">
                                <label for="priority" class="form-label">优先级</label>
                                <select class="form-select" id="priority" name="priority">
                                    {% for priority_code, priority_name in priority_choices %}
                                    <option value="{{ priority_code }}" 
                                            {% if priority_code == todo.priority %}selected{% endif %}>
                                        {{ priority_name }}
                                    </option>
                                    {% endfor %}
                                </select>
                            </div>
                        </div>
                        
                        <div class="mb-3">
                            <label for="due_date" class="form-label">截止时间</label>
                            <input type="datetime-local" class="form-control" id="due_date" name="due_date"
                                   {% if todo.due_date %}value="{{ todo.due_date|date:'Y-m-d\TH:i' }}"{% endif %}>
                        </div>
                        
                        <div class="mb-3">
                            <div class="form-check">
                                <input class="form-check-input" type="checkbox" id="is_completed" 
                                       {% if todo.is_completed %}checked{% endif %} disabled>
                                <label class="form-check-label" for="is_completed">
                                    已完成
                                </label>
                            </div>
                            {% if todo.completed_at %}
                            <small class="text-muted">完成时间: {{ todo.completed_at|date:"Y-m-d H:i" }}</small>
                            {% endif %}
                        </div>
                        
                        <div class="d-grid gap-2 d-md-flex justify-content-md-end">
                            <a href="{% url 'todo:index' %}" class="btn btn-secondary">
                                <i class="bi bi-x-circle"></i> 取消
                            </a>
                            <button type="submit" class="btn btn-primary">
                                <i class="bi bi-check-circle"></i> 保存修改
                            </button>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
{% endblock %}

